package com.droidnova.android.games.vortex;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;

import javax.microedition.khronos.opengles.GL10;

import android.util.Log;

public class points1 {
	// Our vertex buffer.
	FloatBuffer _pvertexBuffer=null;
	//our Color buffer
	FloatBuffer _pcolorBuffer=null;
	
	//noVertices
	int _noVertices=0;
	float _pcolors[]=null , _pvertices[]=null;
	
	short _pindices[]=null;
	
	ShortBuffer indexBuffer=null;
    int setvalue = 0;
    int pindices_length=0;
    int pvertices_length=0;
    int pcolors_length=0;


	public points1(float _pcolors1[] ,float _pvertices1[], int _noVertices1,short[] _pindices1)
	{
		set_noVertices(_noVertices1);
		set_pvertices(_pvertices1);
		set_pcolors(_pcolors1);
		set_pindices(_pindices1);
		setPvertices_length(get_pvertices().length);
		setPcolors_length(get_pcolors().length);
		setPindices_length(get_pindices().length);
		//pindices_length = get_pindices().length;
		//pvertices_length=get_pvertices().length;
		//pcolors_length=get_pcolors().length;
	}
	



	public int getPindices_length() {
		return pindices_length;
	}




	public void setPindices_length(int pindices_length) {
		this.pindices_length = pindices_length;
	}




	public int getPvertices_length() {
		return pvertices_length;
	}




	public void setPvertices_length(int pvertices_length) {
		this.pvertices_length = pvertices_length;
	}




	public int getPcolors_length() {
		return pcolors_length;
	}




	public void setPcolors_length(int pcolors_length) {
		this.pcolors_length = pcolors_length;
	}




	public float[] get_pcolors() {
		return _pcolors;
	}


	public void set_pcolors(float[] _pcolors4) {
		_pcolors = _pcolors4;
	}
	public float[] get_pvertices() {
		return _pvertices;
	}

	public void set_pvertices(float[] _pvertices4) {
		_pvertices = _pvertices4;
	}


	public int get_noVertices() {
		return _noVertices;
	}

	public void set_noVertices(int _noVertices4) {
		_noVertices = _noVertices4;
	}

	public short[] get_pindices() {
		return _pindices;
	}

	public void set_pindices(short[] _pindices2) {
		_pindices = _pindices2;
	}
	
	public void draw(GL10 gl) {
		ByteBuffer vbb=null,cbb=null,ibb=null;
		try
		{
		vbb= ByteBuffer.allocateDirect(get_pvertices().length * 4);
		//vbb= ByteBuffer.allocateDirect(getPvertices_length() * 4);
		vbb.order(ByteOrder.nativeOrder());
		_pvertexBuffer = vbb.asFloatBuffer();
		_pvertexBuffer.clear();
		_pvertexBuffer.put(get_pvertices());
		_pvertexBuffer.position(0);
		
		
		//color buffer
		//vbb.clear();
		cbb = ByteBuffer.allocateDirect(get_pcolors().length * 4);
		//cbb = ByteBuffer.allocateDirect(getPcolors_length() * 4);
		cbb.order(ByteOrder.nativeOrder());
		_pcolorBuffer = cbb.asFloatBuffer();
		_pcolorBuffer.clear();
		_pcolorBuffer.put(get_pcolors());
		_pcolorBuffer.position(0);
		
	    
		ibb = ByteBuffer.allocateDirect(get_pindices().length * 2);
		//ibb = ByteBuffer.allocateDirect(getPindices_length() * 2);
		ibb.order(ByteOrder.nativeOrder());
		indexBuffer = ibb.asShortBuffer();
		indexBuffer.clear();
		//Log.v("ibb","ibb="+ibb.capacity());
		//Log.v("pindices","pindices="+get_pindices().length);
		indexBuffer.put(get_pindices());
		indexBuffer.position(0);
	/*	indexBuffer = ByteBuffer.allocateDirect(get_pindices().length);
	    indexBuffer.put(get_pindices());
	    indexBuffer.position(0);*/ 
		//index buffer
		/*indexBuffer = ByteBuffer.allocateDirect(get_pindices().length);
	    indexBuffer.put(get_pindices());
	    indexBuffer.position(0);*/
		}
		catch(Exception e)
		{
			//vbb.clear();
			vbb= ByteBuffer.allocateDirect(get_pvertices().length * 4);
			vbb.order(ByteOrder.nativeOrder());
			_pvertexBuffer = vbb.asFloatBuffer();
			_pvertexBuffer.clear();
			_pvertexBuffer.put(get_pvertices());
			_pvertexBuffer.position(0);
			
			//cbb.clear();
			cbb = ByteBuffer.allocateDirect(get_pcolors().length * 4);
			cbb.order(ByteOrder.nativeOrder());
			_pcolorBuffer = cbb.asFloatBuffer();
			_pcolorBuffer.clear();
			_pcolorBuffer.put(get_pcolors());
			_pcolorBuffer.position(0);
			
			
			//ibb.clear();
			ibb = ByteBuffer.allocateDirect(get_pindices().length * 2);
			ibb.order(ByteOrder.nativeOrder());
			indexBuffer = ibb.asShortBuffer();
			indexBuffer.clear();
			//Log.v("ibb","ibb="+ibb.capacity());
			//Log.v("pindices","pindices="+get_pindices().length);
			indexBuffer.put(get_pindices());
			indexBuffer.position(0);
			
		}
		
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
	
		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _pvertexBuffer);
		gl.glColorPointer(4, GL10.GL_FLOAT, 0, _pcolorBuffer);
		//set the point size
		gl.glEnable(GL10.GL_POINT_SMOOTH);
        gl.glHint(GL10.GL_POINT_SMOOTH_HINT, GL10.GL_NICEST);
		//gl.glPointSize(5); 
        
		// finally draw the vertices
		// gl.glTranslatef(-0.5f, -0.3f, -0.5f);
		//gl.glRotatef(45.0f, 1.0f,0.0f,1.0f);
		//gl.glDrawArrays(GL10.GL_POINTS, 0,get_noVertices()); 
        if(getSetvalue()==0)
        {
        	gl.glPointSize(5); 
        	gl.glDrawArrays(GL10.GL_POINTS, 0,get_noVertices());
        }
        else if(getSetvalue()==1)
        {
        	
        gl.glDrawElements(GL10.GL_TRIANGLES, get_pindices().length, GL10.GL_UNSIGNED_SHORT, indexBuffer);
        }
		gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
		gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
	}

	public int getSetvalue() {
		return setvalue;
	}


	public void setSetvalue(int setvalue1) {
		setvalue = setvalue1;
	}
}


